<?php

namespace app\qsapi\service;

use app\qsapi\model\BoxMemberAccount;

class AccountService extends BaseService
{


    /**
     * 用户id
     * @param $member_id
     * @return void
     */
    public function getInfo($member_id)
    {
        $memberInfoModel = new BoxMemberAccount();
        $member_info = $memberInfoModel->getInfoByWhere(['member_id' => $member_id]);
        if (!$member_info) {
            $member_info = $this->initMemberAccountInfo($member_id);
        }
        return api_message(is_array($member_info) ? $member_info : $member_info->toArray());
    }

    /**
     * 初始化用户钱包信息
     * @return void
     */
    public function initMemberAccountInfo($member_id)
    {
        $data['member_id'] = $member_id;
        $data['platform_balance'] = 0;
        $data['species_balance'] = 0;
        $data['transaction_balance'] = 0;
        $data['create_time'] = date('Y-m-d H:i:s');
        $data['update_time'] = date('Y-m-d H:i:s');
        $memberInfoModel = new BoxMemberAccount();
        $id = $memberInfoModel->insertRow($data);
        $data['id'] = $id;
        return $data;
    }
}